﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLControlLibrary.Resources.Common;

namespace SLControlLibrary.Resources.Controls.Calendar.DayCalendar
{
    public class ucDayCalendar : Control
    {
        #region Dependency Variables
        private static readonly DependencyProperty MonthDescProperty = DependencyProperty.Register("MonthDesc", typeof(string), typeof(ucDayCalendar), new PropertyMetadata(Utility.FormatDate(Enumerations.DateFormat.ShortMonth, DateTime.Today), new PropertyChangedCallback(MonthDesc_Changed)));
        private static readonly DependencyProperty DayDescProperty = DependencyProperty.Register("DayDesc", typeof(string), typeof(ucDayCalendar), new PropertyMetadata(DateTime.Today.Day.ToString(), new PropertyChangedCallback(DayDesc_Changed)));
        private static readonly DependencyProperty DisplayDateProperty = DependencyProperty.Register("DisplayDate", typeof(DateTime), typeof(ucDayCalendar), new PropertyMetadata(DateTime.Today, new PropertyChangedCallback(DisplayDate_Changed)));
        private static readonly DependencyProperty HeaderBackgroundProperty = DependencyProperty.Register("HeaderBackground", typeof(Brush), typeof(ucDayCalendar), new PropertyMetadata(new SolidColorBrush(Colors.Blue), new PropertyChangedCallback(HeaderBackground_Changed)));
        private static readonly DependencyProperty HeaderForegroundProperty = DependencyProperty.Register("HeaderForeground", typeof(Brush), typeof(ucDayCalendar), new PropertyMetadata(new SolidColorBrush(Colors.White), new PropertyChangedCallback(HeaderForeground_Changed)));
        private static readonly DependencyProperty HeaderBorderBrushProperty = DependencyProperty.Register("HeaderBorderBrush", typeof(Brush), typeof(ucDayCalendar), new PropertyMetadata(Utility.ConvertStringToColor("#FF2D4BB1"), new PropertyChangedCallback(HeaderBorderBrush_Changed)));
        private static readonly DependencyProperty HeaderBorderThicknessProperty = DependencyProperty.Register("HeaderBorderThickness", typeof(Thickness), typeof(ucDayCalendar), new PropertyMetadata(new Thickness(1), new PropertyChangedCallback(HeaderBorderThickness_Changed)));
        private static readonly DependencyProperty ContentBackgroundProperty = DependencyProperty.Register("ContentBackground", typeof(Brush), typeof(ucDayCalendar), new PropertyMetadata(new SolidColorBrush(Colors.Blue), new PropertyChangedCallback(ContentBackground_Changed)));
        private static readonly DependencyProperty ContentForegroundProperty = DependencyProperty.Register("ContentForeground", typeof(Brush), typeof(ucDayCalendar), new PropertyMetadata(new SolidColorBrush(Colors.White), new PropertyChangedCallback(ContentForeground_Changed)));
        private static readonly DependencyProperty ContentBorderBrushProperty = DependencyProperty.Register("ContentBorderBrush", typeof(Brush), typeof(ucDayCalendar), new PropertyMetadata(Utility.ConvertStringToColor("#FF2D4BB1"), new PropertyChangedCallback(ContentBorderBrush_Changed)));
        private static readonly DependencyProperty ContentBorderThicknessProperty = DependencyProperty.Register("ContentBorderThickness", typeof(Thickness), typeof(ucDayCalendar), new PropertyMetadata(new Thickness(1, 4, 1, 1), new PropertyChangedCallback(ContentBorderThickness_Changed)));
        #endregion

        #region Dependency Properties
        public string MonthDesc
        {
            get { return this.GetValue(MonthDescProperty).ToString(); }
            set { this.SetValue(MonthDescProperty, value); }
        }
        public string DayDesc
        {
            get { return this.GetValue(DayDescProperty).ToString(); }
            set { this.SetValue(DayDescProperty, value); }
        }
        public DateTime DisplayDate
        {
            get { return (DateTime)this.GetValue(DisplayDateProperty); }
            set { this.SetValue(DisplayDateProperty, value); }
        }
        public Brush HeaderBackground
        {
            get { return (Brush)this.GetValue(HeaderBackgroundProperty); }
            set { this.SetValue(HeaderBackgroundProperty, value); }
        }
        public Brush HeaderForeground
        {
            get { return (Brush)this.GetValue(HeaderForegroundProperty); }
            set { this.SetValue(HeaderForegroundProperty, value); }
        }
        public Brush HeaderBorderBrush
        {
            get { return (Brush)this.GetValue(HeaderBorderBrushProperty); }
            set { this.SetValue(HeaderBorderBrushProperty, value); }
        }
        public Thickness HeaderBorderThickness
        {
            get { return (Thickness)this.GetValue(HeaderBorderThicknessProperty); }
            set { this.SetValue(HeaderBorderThicknessProperty, value); }
        }
        public Brush ContentBackground
        {
            get { return (Brush)this.GetValue(ContentBackgroundProperty); }
            set { this.SetValue(ContentBackgroundProperty, value); }
        }
        public Brush ContentForeground
        {
            get { return (Brush)this.GetValue(ContentForegroundProperty); }
            set { this.SetValue(ContentForegroundProperty, value); }
        }
        public Brush ContentBorderBrush
        {
            get { return (Brush)this.GetValue(ContentBorderBrushProperty); }
            set { this.SetValue(ContentBorderBrushProperty, value); }
        }
        public Thickness ContentBorderThickness
        {
            get { return (Thickness)this.GetValue(ContentBorderThicknessProperty); }
            set { this.SetValue(ContentBorderThicknessProperty, value); }
        }
        #endregion

        #region Dependency Events
        #region MonthDesc_Changed
        private static void MonthDesc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnMonthDesc_Changed(e);
        }
        #endregion

        #region DayDesc_Changed
        private static void DayDesc_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnDayDesc_Changed(e);
        }
        #endregion

        #region DisplayDate_Changed
        private static void DisplayDate_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnDisplayDate_Changed(e);
        }
        #endregion

        #region HeaderBackground_Changed
        private static void HeaderBackground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnHeaderBackground_Changed(e);
        }
        #endregion

        #region HeaderForeground_Changed
        private static void HeaderForeground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnHeaderForeground_Changed(e);
        }
        #endregion

        #region HeaderBorderBrush_Changed
        private static void HeaderBorderBrush_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnHeaderBorderBrush_Changed(e);
        }
        #endregion

        #region HeaderBorderThickness_Changed
        private static void HeaderBorderThickness_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnHeaderBorderThickness_Changed(e);
        }
        #endregion

        #region ContentBackground_Changed
        private static void ContentBackground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnContentBackground_Changed(e);
        }
        #endregion

        #region ContentForeground_Changed
        private static void ContentForeground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnContentForeground_Changed(e);
        }
        #endregion

        #region ContentBorderBrush_Changed
        private static void ContentBorderBrush_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnContentBorderBrush_Changed(e);
        }
        #endregion

        #region ContentBorderThickness_Changed
        private static void ContentBorderThickness_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayCalendar).OnContentBorderThickness_Changed(e);
        }
        #endregion
        #endregion

        #region Constructor
        public ucDayCalendar()
        {
            DefaultStyleKey = typeof(ucDayCalendar);
        }
        #endregion

        #region Methods
        #region OnMonthDesc_Changed
        protected virtual void OnMonthDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            MonthDesc = e.NewValue.ToString();
        }
        #endregion

        #region OnDayDesc_Changed
        protected virtual void OnDayDesc_Changed(DependencyPropertyChangedEventArgs e)
        {
            DayDesc = e.NewValue.ToString();
        }
        #endregion

        #region OnDisplayDate_Changed
        protected virtual void OnDisplayDate_Changed(DependencyPropertyChangedEventArgs e)
        {
            DisplayDate = (DateTime)e.NewValue;
            MonthDesc = Utility.FormatDate(Enumerations.DateFormat.ShortMonth, DisplayDate);
            DayDesc = DisplayDate.Day.ToString();
        }
        #endregion

        #region OnHeaderBackground_Changed
        protected virtual void OnHeaderBackground_Changed(DependencyPropertyChangedEventArgs e)
        {
            HeaderBackground = (Brush)e.NewValue;
        }
        #endregion

        #region OnHeaderForeground_Changed
        protected virtual void OnHeaderForeground_Changed(DependencyPropertyChangedEventArgs e)
        {
            HeaderForeground = (Brush)e.NewValue;
        }
        #endregion

        #region OnHeaderBorderBrush_Changed
        protected virtual void OnHeaderBorderBrush_Changed(DependencyPropertyChangedEventArgs e)
        {
            HeaderBorderBrush = (Brush)e.NewValue;
        }
        #endregion

        #region OnHeaderBorderThickness_Changed
        protected virtual void OnHeaderBorderThickness_Changed(DependencyPropertyChangedEventArgs e)
        {
            HeaderBorderThickness = (Thickness)e.NewValue;
        }
        #endregion

        #region OnContentBackground_Changed
        protected virtual void OnContentBackground_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentBackground = (Brush)e.NewValue;
        }
        #endregion

        #region OnContentForeground_Changed
        protected virtual void OnContentForeground_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentForeground = (Brush)e.NewValue;
        }
        #endregion

        #region OnContentBorderBrush_Changed
        protected virtual void OnContentBorderBrush_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentBorderBrush = (Brush)e.NewValue;
        }
        #endregion

        #region OnContentBorderThickness_Changed
        protected virtual void OnContentBorderThickness_Changed(DependencyPropertyChangedEventArgs e)
        {
            ContentBorderThickness = (Thickness)e.NewValue;
        }
        #endregion
        #endregion
    }
}
